#include <iostream>
#include <vector>

using namespace std;

int eatenApples(vector<int>& apples, vector<int>& days) {
    int len = apples.size();
    int day = 0;
    int cnt = 0;
    int bad[20005] = {};

    for (int i = 0; i < len; i++) {
        bad[i] = i + days[i];
    }


cout << "1111" << endl;

    for(int day=0;day<=20;day++){
        for (int i = 0; i < len; i++) {
            if (bad[i] <= day) {
                apples[i] = 0;
            }
        }

cout << "2222" << endl;

        int minbad = 2147483647;
        int minindex;
        for (int i = 0; i <= day; i++) {
            if (apples[i] > 0 && bad[i] < minbad) {
                minbad = bad[i];
                minindex = i;
            }
        }
cout << "3333" << endl;
        if (minbad != 2147483647) {
cout << "minbad = " << minbad <<endl;            

            apples[minindex]--;
            cnt++;
cout << "cnt = " << cnt <<endl;            
        }
    }



    return cnt;
}

int main() {
    int a[5] = {1,2,3,5,2};
    int b[5] = {3,2,1,4,2};
    vector<int> apples(a,a+5);
    vector<int> days(b,b+5);
    
    cout << eatenApples(apples,days) << endl;

    return 0;
}